home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d949.lha / BBBBS / BBBBS65.lha / rexx / BuildALPHA.rexx < prev    next >
OS/2 REXX Batch file  |  1993-10-04  |  10KB  |  385 lines

  1. /* $VER: BuildALPHA.rexx 6.4 (4.10.93)
  2. copyright 1990-93 Richard Lee Stockton
  3.          FREELY DISTRIBUTABLE
  4.  
  5.    Build the main filelist "Lists/Files" from the filenotes,
  6. then build "Lists/Files.ALPHA" from that list and the filenotes.
  7.  
  8. KeyWords field (if empty) is built from the long description (if any).
  9. Bytes field is corrected (if necessary) to match real filesize.
  10.  
  11. If COLLECT is passed as an argument, will collect files that have
  12. no file description and construct descriptions for them using the
  13. filecomment of the file (if any) for note data. Note that the
  14. filecomment is then blanked so it won't interfere with displays.
  15.  
  16. IF NOFILEBUILD is passed the argument, only the ALPHA list is rebulit.
  17. */
  18.  
  19. ARG collectflag .
  20.  
  21. IF collectflag='?' THEN
  22.   DO
  23.     DO i=1 TO 14
  24.       SAY SOURCELINE(i)
  25.     END
  26.     EXIT
  27.   END
  28.  
  29.  
  30. /* If the QuickSortPort not found then try to run setup.rexx */
  31.  
  32. IF ~show('P','QuickSortPort') THEN CALL setup.rexx()
  33. IF ~show('P','QuickSortPort') THEN CALL GETOUT(666)
  34.  
  35. figarg='s:CONFIG.BBS'
  36. IF ~EXISTS(figarg) THEN figarg='BBS:BBS_TEXT/CONFIG.BBS'
  37. x=OPEN(f,figarg,'R')
  38. IF x=0 THEN
  39.   DO
  40.     SAY 's:CONFIG.BBS and BBS:BBS/CONFIG.BBS are both missing!'
  41.     EXIT(20)
  42.   END
  43.  
  44. lynes.=''
  45. DO i=1 TO 8
  46.   lynes.i=READLN(f)
  47. END
  48. CALL CLOSE(f)
  49.  
  50. compos=POS('/*',lynes.1)
  51. IF compos>0 THEN lynes.1=LEFT(lynes.1,compos-1)
  52.  
  53. bbsname = STRIP(lynes.1)
  54. sysop   = WORD(lynes.2,1)
  55. bbspath = WORD(lynes.6,1)
  56. IF ~EXISTS(bbspath) THEN
  57.   DO
  58.     SAY 'The bbspath, 'bbspath', does not exist!'
  59.     EXIT(21)
  60.   END
  61. testchar=RIGHT(bbspath,1)
  62. IF testchar~='/' & testchar~=':' THEN bbspath=bbspath'/'
  63. libpath = WORD(lynes.8,1)
  64. IF ~EXISTS(libpath) THEN
  65.   DO
  66.     SAY 'The library path, 'libpath', does not exist!'
  67.     EXIT(22)
  68.   END
  69. testchar=RIGHT(libpath,1)
  70. IF testchar~='/' & testchar~=':' THEN libpath=libpath'/'
  71.  
  72. IF SHOW('P','BBBBS') THEN CALL PRAGMA('P',-2)
  73. etime=TIME('R')
  74.  
  75. IF collectflag='COLLECT' THEN
  76.   DO
  77.     OPTIONS PROMPT 'Shall I clear each filecomment after using in the description? (Yn) > '
  78.     PULL clearflag .
  79.     clearflag=LEFT(STRIP(clearflag),1)
  80.     SAY 'Searching for files with no file descriptions...'
  81.     filelibs=SHOWDIR(libpath,'D')
  82.     DO i=1 TO WORDS(filelibs)
  83.       thislib=WORD(filelibs,i)
  84.       realfiles=SHOWDIR(libpath||thislib)
  85.       DO j=1 TO WORDS(realfiles)
  86.         thisfile=WORD(realfiles,j)
  87.         IF ~EXISTS(bbspath'FileNotes/'thislib'/'thisfile) THEN CALL makenote
  88.       END
  89.     END
  90.     IF ~DATATYPE(lastfile,'N') THEN
  91.       DO
  92.         SAY 'All files in the libraries have descriptions.'
  93.         EXIT
  94.       END
  95.   END
  96.  
  97. IF collectflag~='NOFILEBUILD' | ~EXISTS(bbspath'Lists/Files') THEN
  98.   DO
  99.     libs=SHOWDIR(bbspath'FileNotes','D')
  100.     lynes.=''
  101.     latest=0
  102.     SAY 'Building Files list.'
  103.     DO i=1 TO WORDS(libs)
  104.       lib=WORD(libs,i)
  105.       notes=SHOWDIR(bbspath'FileNotes/'lib,'F')
  106.       DO j=1 TO WORDS(notes)
  107.         note=WORD(notes,j)
  108.         file=libpath||lib'/'note
  109.         IF ~EXISTS(file) THEN
  110.           DO
  111.             temp=WORD(STATEF(bbspath'FileNotes/'lib'/'note),8)
  112.             IF temp~='' THEN file=temp
  113.             IF ~EXISTS(file) THEN SAY file 'does not exist.'
  114.           END
  115.         IF OPEN(f,bbspath'FileNotes/'lib'/'note,'R')=0 THEN
  116.           DO
  117.             IF EXISTS(file) THEN
  118.               SAY 'Could not open file description for' lib'/'note
  119.             ELSE SAY libpath||lib'/'note 'does not exist.'
  120.             ITERATE j
  121.           END
  122.         line=READLN(f)
  123.         filenum=WORD(line,2)
  124.         IF ~DATATYPE(filenum,'N') THEN
  125.           DO
  126.             SAY '*** Bad file description!' lib'/'note
  127.             SAY line
  128.             ITERATE j
  129.           END
  130.         filenum=filenum%1
  131.         line=READLN(f)
  132.         filename=STRIP(WORD(line,2))
  133.         CALL CLOSE(f)
  134.         IF UPPER(filename)~=UPPER(note) THEN
  135.           DO
  136.             SAY 'Name: field does not match actual filename!'
  137.             SAY 'Changing Name: 'filename' in file description to 'note
  138.             x=OPEN(f,bbspath'FileNotes/'lib'/'note,'R')
  139.             IF x=0 THEN EXIT 20
  140.             text.=''
  141.             DO i=1
  142.               x=READLN(F)
  143.               IF EOF(f) THEN LEAVE i
  144.               text.i=x
  145.             END
  146.             CALL CLOSE(f)
  147.             text.0=i-1
  148.             text.2=OVERLAY(note,text.2,7,27)
  149.             CALL DELAY(50)
  150.             x=OPEN(f,bbspath'FileNotes/'lib'/'note,'W')
  151.             IF x=0 THEN EXIT 20
  152.             DO i=1 TO text.0
  153.               CALL WRITELN(f,text.i)
  154.             END
  155.             CALL CLOSE(f)
  156.             filename=note
  157.           END
  158.         IF lynes.filenum~='' THEN
  159.           SAY 'Duplicate file numbers! 'filenum lynes.filenum '&' lib filename
  160.         lynes.filenum=lib filename
  161.         IF filenum>latest THEN latest=filenum
  162.       END
  163.     END
  164.     CALL SETCLIP('BBS_maint','File-Building')
  165.     SAY 'Writing Files list.'
  166.     x=OPEN(f,bbspath'Lists/Files','W')
  167.     IF x=0 THEN
  168.       DO
  169.         SAY '*** Failure!  Error opening' bbspath'Lists/Files'
  170.         CALL GETOUT(23)
  171.       END
  172.     DO i=1 TO latest
  173.       IF lynes.i='' THEN ITERATE i
  174.       CALL WRITELN(f,i lynes.i)
  175.     END
  176.     CALL CLOSE(f)
  177.     CALL SETCLIP('BBS_maint')
  178.   END
  179.  
  180. SAY 'Reading Libraries list.'
  181.  
  182. x=OPEN(f,bbspath'Lists/Libraries','R')
  183. IF x=0 THEN CALL GETOUT(24);
  184. libs.=''
  185. DO i=1
  186.   line=READLN(f)
  187.   IF EOF(f) THEN LEAVE i
  188.   indx=WORD(line,1)
  189.   IF ~DATATYPE(indx,'N') THEN ITERATE i
  190.   libname=UPPER(WORD(line,2))
  191.   libs.libname=indx
  192. END
  193. CALL CLOSE(f)
  194.  
  195. SAY 'Reading Files list.'
  196.  
  197. x=OPEN(f,bbspath'Lists/Files','R')
  198. IF x=0 THEN CALL GETOUT(25);
  199. lynes.=''
  200. DO i=1
  201.   line=READLN(f)
  202.   IF EOF(f) THEN LEAVE i
  203.   lynes.i=line
  204. END
  205. CALL CLOSE(f)
  206. lynes.0=i-1
  207.  
  208. SAY 'Building Files.ALPHA list.'
  209.  
  210. DO i=1 TO lynes.0
  211.   num=WORD(lynes.i,1)
  212.   lib=WORD(lynes.i,2)
  213.   libname=UPPER(lib)
  214.   file=WORD(lynes.i,3)
  215.   fullfile=libpath||lib'/'file
  216.   IF ~EXISTS(fullfile) THEN
  217.     DO
  218.       temp=WORD(STATEF(bbspath'FileNotes/'lib'/'file),8)
  219.       IF temp~='' THEN fullfile=temp
  220.       IF ~EXISTS(fullfile) THEN SAY fullfile 'does not exist.'
  221.     END
  222.   IF OPEN(f,bbspath'FileNotes/'lib'/'file,'R')=0 THEN
  223.     DO
  224.       IF EXISTS(fullfile) THEN
  225.         SAY 'Could not find filenote for' lib'/'file '!'
  226.       ELSE SAY fullfile 'has neither file nor note!'
  227.       ITERATE i
  228.     END
  229.   line=READLN(f)
  230.   PARSE VAR line . 'KeyWords:' keywords
  231.   notebytes=WORD(READLN(f),4)
  232.   IF LENGTH(keywords)<3 THEN
  233.     DO
  234.       CALL READLN(f)
  235.       CALL READLN(f)
  236.       line=READLN(f)
  237.       CALL CLOSE(f)
  238.       IF line~='' THEN
  239.         DO
  240.           keywords=STRIP(LEFT(line,32))
  241.           CALL fixkeywords()
  242.         END
  243.     END
  244.   ELSE CALL CLOSE(f)
  245.   bytes=0
  246.   IF EXISTS(fullfile) THEN
  247.     DO
  248.       bytes=WORD(STATEF(fullfile),2)
  249.       IF bytes~=notebytes THEN CALL fixbytes()
  250.     END
  251.   ELSE bytes=notebytes
  252.   lynes.i=LEFT(file,22-LENGTH(bytes)) bytes RIGHT(num,5) RIGHT(libs.libname,2)
  253.   lynes.i=lynes.i LEFT(lib,12) TRIM(LEFT(STRIP(keywords),32))
  254. END
  255.  
  256. SAY 'Sorting Files.ALPHA list.'
  257.  
  258. CALL QSORT(1,lynes.0,lynes)
  259.  
  260. SAY 'Saving Files.ALPHA list.'
  261.  
  262. CALL SETCLIP('BBS_maint','File-Building')
  263. x=OPEN(f,bbspath'Lists/Files.ALPHA','W')
  264. IF x=0 THEN CALL GETOUT(25)
  265. DO i=1 TO lynes.0
  266.   CALL WRITELN(f,lynes.i)
  267. END
  268. CALL CLOSE(f)
  269. CALL SETCLIP('BBS_maint')
  270. CALL GETOUT(0)
  271. EXIT
  272.  
  273.  
  274. GETOUT:
  275. ARG outnum .
  276. CALL SETCLIP('BBS_maint')
  277. IF outnum>0 THEN SAY 'Error number' outnum'.  Refer to BuildALPHA.rexx'
  278. mins=TIME('E')%60
  279. secs=TRUNC(TIME('E')//60)
  280. IF secs<10 THEN secs='0'secs
  281. SAY 'Elapsed time file building =' mins':'secs
  282. EXIT(outnum);
  283.  
  284.  
  285. fixkeywords:
  286. SAY 'Fixing keywords field for' lib'/'file
  287. fixfile=bbspath'FileNotes/'lib'/'file
  288. finfo=STATEF(fixfile)
  289. comment=''
  290. IF WORDS(finfo)>7 THEN comment=STRIP(SUBSTR(finfo,WORDINDEX(finfo,8)))
  291. fxlines.=''
  292. x=OPEN(f,fixfile,'R')
  293. IF x=0 THEN
  294.   DO
  295.     SAY 'Failed to open' fixfile 'for reading! (keywords adjustment)'
  296.     RETURN
  297.   END
  298. DO fx=1
  299.   line=READLN(f)
  300.   IF EOF(f) THEN LEAVE fx
  301.   fxlines.fx=line
  302. END
  303. CALL CLOSE(f)
  304. fxlines.0=fx-1
  305. fxlines.1=OVERLAY('KeyWords:' keywords,fxlines.1,WORDINDEX(fxlines.1,3),LENGTH(keywords)+10)
  306. x=OPEN(f,fixfile,'W')
  307. IF x=0 THEN
  308.   DO
  309.     SAY 'Failed to open' fixfile 'for writing! (keywords adjustment)'
  310.     RETURN
  311.   END
  312. DO fx=1 TO fxlines.0
  313.   CALL WRITELN(f,fxlines.fx)
  314. END
  315. CALL CLOSE(f)
  316. IF comment~='' THEN ADDRESS COMMAND 'filenote' fixfile comment
  317. RETURN
  318.  
  319.  
  320. fixbytes:
  321. SAY 'Fixing bytes field for' lib'/'file
  322. fixfile=bbspath'FileNotes/'lib'/'file
  323. finfo=STATEF(fixfile)
  324. comment=''
  325. IF WORDS(finfo)>7 THEN comment=STRIP(SUBSTR(finfo,WORDINDEX(finfo,8)))
  326. fxlines.=''
  327. x=OPEN(f,fixfile,'R')
  328. IF x=0 THEN
  329.   DO
  330.     SAY 'Failed to open' fixfile 'for reading! (byte adjustment)'
  331.     RETURN
  332.   END
  333. DO fx=1
  334.   line=READLN(f)
  335.   IF EOF(f) THEN LEAVE fx
  336.   fxlines.fx=line
  337. END
  338. CALL CLOSE(f)
  339. fxlines.0=fx-1
  340. fxlines.2=OVERLAY(bytes,fxlines.2,WORDINDEX(fxlines.2,4),LENGTH(bytes)+1)
  341. x=OPEN(f,fixfile,'W')
  342. IF x=0 THEN
  343.   DO
  344.     SAY 'Failed to open' fixfile 'for writing! (byte adjustment)'
  345.     RETURN
  346.   END
  347. DO fx=1 TO fxlines.0
  348.   CALL WRITELN(f,fxlines.fx)
  349. END
  350. CALL CLOSE(f)
  351. IF comment~='' THEN ADDRESS COMMAND 'filenote' fixfile comment
  352. RETURN
  353.  
  354.  
  355. makenote:
  356. CALL MAKEDIR(bbspath'FileNotes/'thislib)
  357. x=OPEN(f,bbspath'FileNotes/'thislib'/'thisfile,'W')
  358. IF x=0 THEN
  359.   DO
  360.     SAY bbspath'FileNotes/'thislib'/'thisfile 'failed to open!'
  361.     RETURN
  362.   END
  363. x=OPEN(ff,bbspath'Numbers/LastFile','R')
  364. IF x~=0 THEN lastfile=READLN(ff)+1
  365. ELSE lastfile=1
  366. CALL CLOSE(ff)
  367. ADDRESS COMMAND 'ECHO >'bbspath'Numbers/LastFile 'lastfile
  368. finfo=STATEF(libpath||thislib'/'thisfile)
  369. bytes=WORD(finfo,2)
  370. comment=''
  371. IF WORDS(finfo)>7 THEN comment=STRIP(SUBSTR(finfo,WORDINDEX(finfo,8)))
  372. CALL WRITELN(f,'File: 'LEFT(lastfile,5)' KeyWords:' STRIP(LEFT(comment,31)))
  373. CALL WRITELN(f,'Name: 'LEFT(thisfile,27)' Size: 'bytes' bytes   Downloads: 0')
  374. CALL WRITELN(f,'From: 'LEFT(sysop,27)' Date: 'DATE() TIME('C')'  Lib: 'thislib)
  375. CALL WRITELN(f,LEFT('',74,'='))
  376. IF LENGTH(comment)>31 THEN CALL WRITELN(f,comment)
  377. CALL CLOSE(f)
  378. IF comment~='' & clearflag~='N' THEN
  379.   ADDRESS COMMAND 'filenote' libpath||thislib'/'thisfile '22'x||'22'x
  380. SAY 'Added' thisfile 'to the' thislib 'library.'
  381. RETURN
  382.  
  383.  
  384. /* Build ALPHA.rexx */
  385.